//#include "SST89x5xxRD2.H"
#include "lpc2478_lcd.h"

 uint8_t code BMP[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x18,0x08,0x08,0xF8,0x08,
0x08,0x18,0x00,0xE0,0x10,0x08,0x08,0x08,
0x10,0xE0,0x00,0x08,0xF8,0x08,0x08,0x08,
0x08,0xF0,0x00,0xF8,0x08,0x00,0xF8,0x00,
0x08,0xF8,0x00,0x00,0x00,0xC0,0x38,0xE0,
0x00,0x00,0x00,0x08,0x38,0xC8,0x00,0xC8,
0x38,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0xF8,0x08,0x00,0x00,
0x00,0x00,0x00,0x08,0xF8,0xF8,0x00,0xF8,
0xF8,0x08,0x00,0x00,0xE0,0x10,0x88,0x88,
0x18,0x00,0x00,0x00,0x70,0x88,0x08,0x08,
0x88,0x70,0x00,0x00,0xE0,0x10,0x08,0x08,
0x10,0xE0,0x00,0x00,0xE0,0x10,0x08,0x08,
0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0xF8,0x08,0x00,0x00,
0x00,0x00,0x00,0xC0,0x30,0x08,0x08,0x08,
0x08,0x38,0x00,0x08,0xF8,0x08,0x08,0x08,
0x10,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x08,0xF8,0xF8,0x00,0xF8,
0xF8,0x08,0x00,0x00,0x00,0x80,0x80,0x80,
0x80,0x00,0x00,0x00,0x00,0x00,0x80,0x80,
0x88,0xF8,0x00,0x80,0x80,0x00,0x00,0x00,
0x80,0x80,0x00,0x00,0x08,0x08,0xF8,0x00,
0x00,0x00,0x00,0x00,0x00,0x80,0x80,0x80,
0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x20,0x3F,0x20,
0x00,0x00,0x00,0x0F,0x10,0x20,0x20,0x20,
0x10,0x0F,0x00,0x20,0x3F,0x21,0x01,0x01,
0x01,0x00,0x00,0x03,0x3C,0x07,0x00,0x07,
0x3C,0x03,0x00,0x20,0x3C,0x23,0x02,0x02,
0x27,0x38,0x20,0x00,0x00,0x20,0x3F,0x20,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,
0x20,0x30,0x00,0x20,0x3F,0x00,0x3F,0x00,
0x3F,0x20,0x00,0x00,0x0F,0x11,0x20,0x20,
0x11,0x0E,0x00,0x00,0x1C,0x22,0x21,0x21,
0x22,0x1C,0x00,0x00,0x0F,0x10,0x20,0x20,
0x10,0x0F,0x00,0x00,0x0F,0x10,0x20,0x20,
0x10,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x3F,0x20,0x20,0x20,
0x20,0x30,0x00,0x07,0x18,0x20,0x20,0x20,
0x10,0x08,0x00,0x20,0x3F,0x20,0x20,0x20,
0x10,0x0F,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x20,0x3F,0x00,0x3F,0x00,
0x3F,0x20,0x00,0x00,0x1F,0x20,0x20,0x20,
0x20,0x1F,0x00,0x00,0x0E,0x11,0x20,0x20,
0x10,0x3F,0x20,0x00,0x1F,0x20,0x20,0x20,
0x10,0x3F,0x20,0x00,0x20,0x20,0x3F,0x20,
0x20,0x00,0x00,0x00,0x1F,0x22,0x22,0x22,
0x22,0x13,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};




 void main()
 {
	uint16_t i,j,k;
//	uint16_t n;
	uint8_t status = 0;
	uint8_t hello[] ="Hello World!" ;
	//while(1);
	LCD_CSC = 1;
	LCD_CSB = 1;
	LCD_CSA = 1;
	LCD_RST = 1;
	LCD_RS = 1;
	LCD_E = 1;
	LCD_DATA_BUS = 0xff;
	LCD_Init();	  
	//LCD_Write_Char(0xaa);


	/*for(k=0;k<4;k++)
	{
		LCD_Chip_Select(k);
		//оƬѡ��
		for(j=0;j<8;j++)
		{
			LCD_Write_CMD(0xb8+j);
			//ҳ��ַ����
			LCD_Write_CMD(0x40);
			//�е�ַ����
			for(i=0;i<64;i++)
				LCD_Write_Char(0x00);
		}
	}*/
	xdev_out(LCD_PutCode);
	//xfunc_out = (void (*)(unsigned char))(LCD_PutCode);
	//xfunc_out =  (LCD_PutCode);
	LCD_ClrScreen();
	//LCD_Locate();
	Delay(200);
	//LCD_Read_Char();
	/*for(k=0;k<16;k++)
	{
		for(j=0;j<12;j++)
		{
			LCD_PutDot(k*4,4*j,1);
		}
	}
	Delay(10000);*/
	/*for(k=0;k<4;k++)
	{
		LCD_Chip_Select(k);	   //оƬѡ��
		for(j=0;j<4;j++)
		{
			LCD_Write_CMD(0xb8+2*j);	 //ҳ��ַ����
			//while (LCD_Read_Status() & 0x80);
			LCD_Write_CMD(0x40);		//�е�ַ����
			for(i=0;i<64;i++)
			{
				n=i+64*k;
				//while (LCD_Read_Status() & 0x80);
				LCD_Write_Char(gl_asckey8X8[n]);

			}
		}

	}*/
	LCD_Locate(6,230);
	/*LCD_PutAsc(ASC_8X16,'{');
	LCD_PutAsc(ASC_8X16,'A');
	LCD_PutAsc(ASC_8X8,'B');
	LCD_PutAsc(ASC_8X8,'\n');
	LCD_PutAsc(ASC_8X8,'C');
	LCD_PutAsc(ASC_8X8,'d');
	LCD_PutAscStr(ASC_8X8,"\b\b\b\b\b\b");
	LCD_PutAscStr(ASC_8X8,&hello[0]);
	LCD_PutAscStr(ASC_8X8,"\n");*/
	LCD_PutAscStr(ASC_16X16,&hello[0]);
	LCD_PutAscStr(ASC_16X16,"\b\b\b\b\b");
	//LCD_PutAscStr(ASC_16X16,"TEST");
	xputs("     ");
	//xprintf("Hello!");
	j = 10;
	xprintf("r:%d,%b c:%s\n",gl_curRow,gl_curRow,&hello[0]);

	//Delay(5000);
	/*LCD_CHIP_SEL_3();//LCD_Chip_Select(0);
	LCD_Write_CMD(0xb8+0);	 //ҳ��ַ����
	LCD_Write_CMD(0x40);		//�е�ַ����
	LCD_Write_CMD(LCD_DISPLAY_START_ADDR|0x0);
	for(i=0;i<32;i++)
	{
		LCD_Write_Char(nihao[i]);
	}*/
	/*LCD_CHIP_SEL_1();//LCD_Chip_Select(1);
	LCD_Write_CMD(0xb8+2);	 //ҳ��ַ����
	LCD_Write_CMD(0x40);		//�е�ַ����
	LCD_Write_CMD(LCD_DISPLAY_START_ADDR|0x0);
	for(i=0;i<32;i++)
	{
		LCD_Write_Char(nihao[i]);
	}
	LCD_CHIP_SEL_2();//LCD_Chip_Select(0);
	LCD_Write_CMD(0xb8+4);	 //ҳ��ַ����
	LCD_Write_CMD(0x40);		//�е�ַ����
	LCD_Write_CMD(LCD_DISPLAY_START_ADDR|0x0);
	for(i=0;i<32;i++)
	{
		LCD_Write_Char(nihao[i]);
	}
	LCD_CHIP_SEL_3();//LCD_Chip_Select(1);
	LCD_Write_CMD(0xb8+6);	 //ҳ��ַ����
	LCD_Write_CMD(0x40);		//�е�ַ����
	LCD_Write_CMD(LCD_DISPLAY_START_ADDR|0x0);
	for(i=0;i<32;i++)
	{
		LCD_Write_Char(nihao[i]);
	}*/

	
	
	//LCD_Locate(2,201);
	//LCD_Write_CMD(LCD_DISPLAY_START_ADDR|0x0);
	/*for(i=0;i<10;i++)
	{
		
		//while (LCD_Read_Status() & 0x80);
		LCD_Locate(2,i*4);
		LCD_Write_Char(0xa5);
		LCD_Write_Char(0x5a);
		LCD_Locate(25,i*4);
		LCD_Write_Char(0xa5);
		LCD_Write_Char(0x5a);
		LCD_Locate(46,i*4);
		LCD_Write_Char(0xa5);
		LCD_Write_Char(0x5a); 
		/*LCD_Chip_Select(k);	   //оƬѡ��
		LCD_Write_CMD(0xb8+j);
			//ҳ��ַ����
		LCD_Write_CMD(0x40);
		for(k=0;k<8;i++){
			LCD_Write_Char
		} */
		
	//}
	/*for(k=0;k<4;k++)
	{
		LCD_Chip_Select(k);	   //оƬѡ��
		for(j=0;j<4;j++)
		{
			LCD_Chip_Select(k);	   //оƬѡ��
			//while (LCD_Read_Status() & 0x80);
			LCD_Write_CMD(0xb8+2*j);	 //ҳ��ַ����
			//while (LCD_Read_Status() & 0x80);
			LCD_Write_CMD(0x40);		//�е�ַ����
			for(i=0;i<64;i++)
			{
				n=2*i+128*k;
				//while (LCD_Read_Status() & 0x80);
				LCD_Write_Char(num[n]);
				
			}
			LCD_Write_CMD(0xb8+2*j+1);	 //ҳ��ַ����
			//while (LCD_Read_Status() & 0x80);
			LCD_Write_CMD(0x40);		//�е�ַ����
			for(i=0;i<64;i++)
			{
				n=2*i+128*k+1;
				//while (LCD_Read_Status() & 0x80);
				LCD_Write_Char(num[n]);
				
			}
		} 

	}*/
	
	//LCD_Write_CMD(LCD_DISPLAY_START_ADDR|0x0);

	Delay(10000);
	/*for(k=0;k<4;k++)
	{
		LCD_Chip_Select(k);	   //оƬѡ��
		for(j=0;j<8;j++)
		{
			//LCD_Chip_Select(k);	   //оƬѡ��
			//while (LCD_Read_Status() & 0x80);
			LCD_Write_CMD(0xb8+j);	 //ҳ��ַ����
			//while (LCD_Read_Status() & 0x80);
			LCD_Write_CMD(0x40);		//�е�ַ����
			for(i=0;i<64;i++)
			{
				n=i+256*(j%2)+64*k;
				//while (LCD_Read_Status() & 0x80);
				LCD_Write_Char(BMP[n]);
				
			}
		} 

	}*/
	 
	 


	/*	for(k=4;k>0;k--)
	{
		LCD_Chip_Select(k-1);	   //оƬѡ��
		for(j=0;j<8;j++)
		{
			//while (LCD_Read_Status() & 0x80);
			LCD_Write_CMD(0xb8+j);	 //ҳ��ַ����
			//while (LCD_Read_Status() & 0x80);
			LCD_Write_CMD(0x40);		//�е�ַ����
			for(i=0;i<64;i++)
			{
				n=i+256*(j%2)+64*(k-1);
				//while (LCD_Read_Status() & 0x80);
				LCD_Write_Char(BMP[n]);
			}
		} 

	}  */
	i = 0;
	while(1){
		LCD_CSB = 0;
		LCD_CSA = 0;
		Delay(100);
		LCD_CSA = 1;
		LCD_CSB = 1;
		Delay(100);
		i = (i > 64)?0:i;
		i++;
		for (k=0;k<4;k++){
			LCD_Chip_Select(k);	   //оƬѡ��
			LCD_Write_CMD(LCD_DISPLAY_START_ADDR|i);
		}
		
	}
	while(1);

 }
void Delay(uint16_t t)
{
	volatile  uint16_t i;
	volatile uint16_t j;
	volatile uint16_t k;

	for(j=0;j<t;j++){
		for(i=0;i<109;i++)
		{
			 k =i;
		}
	}
}
